package com.woniuxy.dr_mall.controller;

import com.woniuxy.dr_mall.entity.DrPicture;
import com.woniuxy.dr_mall.entity.DrProducts;
import com.woniuxy.dr_mall.service.IDrProductsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 张哲轩
 * @version 1.0.0
 * @ClassName WelcomeController.java
 * @createTime 2021年08月15日 22:11:00
 */
@Controller
@Slf4j
public class WelcomeController {
    @Autowired
    private IDrProductsService drProductsService;
    @GetMapping("/")
    public String hello(Model model){
        String popular="y";
        List<DrProducts> products = drProductsService.getByPopular(popular);
        if(products.size() > 3){
            products = products.subList(0, 4);//重新给list赋值
        }
        for (DrProducts product : products) {
            product.setMinPrice(drProductsService.getMinPrice(product.getId()));
        }
        model.addAttribute("products",products);
        log.debug("products:{}",products);
        return "index";
    }



}
